package com.example.springbootdeom.dao;

import com.example.springbootdeom.entity.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ManageDao {

    //添加用户
    @Insert("INSERT INTO `user`(uname,password,birthday,sex,age,status,name) VALUES(#{uname},#{password},#{birthday},#{sex},#{age},#{status},#{name});")
    public boolean addUser(User u);
    //删除用户
    @Delete("DELETE FROM `user` WHERE id =#{id}")
    public  boolean deleteUser(int id);
    //修改
    @Update("UPDATE `user` AS u SET uname=#{uname},sex=#{sex},age=#{age},birthday=#{birthday},`name`=#{name} WHERE id=#{id}")
    public boolean modify(User u);

    //查询全部用户
    @Select("SELECT u.id,u.`name`,u.uname,u.`password`,u.sex,u.age,u.birthday,s.`status`  FROM `user` AS u LEFT JOIN `status` AS s ON u.`status`=s.status_id ")
    public List<User> getUser();
    //查询全部学生
    @Select("SELECT u.id,u.`name`,u.uname,u.`password`,u.sex,u.age,u.birthday,s.`status`  FROM `user` AS u LEFT JOIN `status` AS s ON u.`status`=s.status_id WHERE u.`status`=2")
    public List<Student> getStudent();

    //查询全部老师
    @Select("SELECT u.id,u.`name`,u.uname,u.`password`,u.sex,u.age,u.birthday,s.`status`,u.wages  FROM `user` AS u LEFT JOIN `status` AS s ON u.`status`=s.status_id WHERE u.`status`=1")
    public List<Teacher> getTeacher();

    //查询全部管理员
    @Select("SELECT u.id,u.`name`,u.uname,u.`password`,u.sex,u.age,u.birthday,s.`status`  FROM `user` AS u LEFT JOIN `status` AS s ON u.`status`=s.status_id WHERE u.`status`=0")
    public List<Admin> getAdmin();

    //加入班级(需要传用户id 加入成功返回true)
    @Insert("UPDATE `user` SET class_id=2 WHERE id=#{id} AND `status`=2")
    public boolean addClass(int id);

    //查询所有班级
    @Select("SELECT c.class_id AS id,c.class_name AS name,count FROM class AS c;")
    public List<Classs> getAllClass();
    //查询全校所有的课程
    @Select("SELECT * FROM course;")
    public List<Course> getAllCourse();
    //修改用户密码(传入用户id)
    @Update("UPDATE `user` SET password=#{password} WHERE id=#{id}")
    public boolean setPassword(@Param("password") String password,@Param("id") int id);

    //查询用户密码
    @Select("SELECT password from `user` WHERE id =#{id};")
    public String getOldPassword(int id);
}
